copy (choose application with prompt "What application would you like to choose a menu item from?") to apl copy text returned of (display dialog "What is the name of the menu in which the menu item is?" default answer "") to MenuName copy text returned of (display dialog "What is the name of the item in the " & MenuName & " menu that you would like to choose?" default answer "") to ItemName doMenuName(apl, MenuName, ItemName) on doMenuName(apl, MenuName, ItemName) copy false to foundmenu copy false to founditem copy (QueryMenuList(apl)) to menulist if item 1 of menulist is "error" then display dialog (item 2 of menulist) buttons {"Abort"} default button "Abort" else repeat with cycle from 1 to (number of items in menulist) if (Çclass mntiÈ of item cycle of menulist) is MenuName then copy true to foundmenu copy (QueryMenu(apl, (Çclass mnidÈ of item cycle of menulist))) to itemlist if item 1 of itemlist is "error" then display dialog (item 2 of itemlist) buttons {"Abort"} default button "Abort" else repeat with cycle2 from 1 to (number of items in itemlist) if (Çclass miteÈ of item cycle2 of itemlist) is ItemName then copy true to founditem copy (DoMenuItem(apl, (Çclass mnidÈ of item cycle of menulist), (Çclass miidÈ of item cycle2 of itemlist))) to theResult if item 1 of theResult is "error" then display dialog (item 2 of theResult) buttons {"Abort"} default button "Abort" end if exit repeat end if end repeat end if exit repeat end if end repeat end if if foundmenu is false then display dialog "The menu \"" & MenuName & "\" was not found in the application \"" & apl & "\"." end if if (founditem is false) and (foundmenu is true) then display dialog "The menu item \"" & ItemName & "\" was not found in the menu \"" & MenuName & "\" in the application \"" & apl & "\"." end if end doMenuName on QueryMenuList(apl) try tell apl return (Çevent M¾nuqmn#È) end tell on error (errID) copy word ((number of words in errID) - 2) of errID to errID if errID = "126" then copy "A Menu Events error occurred. The specified application (" & apl & ") has no menu bar." to errText else copy "" to errText end if if errText is "" then return errID else return {"error", errText} end if end try end QueryMenuList on QueryMenu(apl, MenuID) try tell apl return (Çevent M¾nuqmn È given Çclass mnidÈ:MenuID) end tell on error (errID) copy "" to errText copy word ((number of words in errID) - 2) of errID to errID if errID = "126" then copy "A Menu Events error occurred. The specified application (" & apl & ") has no menu bar." to errText end if if errID = "21000" then copy "A Menu Events error occurred. The specified application (" & apl & ") has no such menu (menu id " & MenuID & " was specified)." to errText end if if errID = "21004" then copy "A Menu Events error occurred. The specified application (" & apl & ") does not support High Level Events." to errText end if if errText = "" then return errID else return {"error", errText} end if end try end QueryMenu on DoMenuItem(apl, MenuID, MenuItemID) try tell apl Çevent M¾nusemiÈ given Çclass mnidÈ:MenuID, Çclass miidÈ:MenuItemID end tell return {""} on error (errID) copy word ((number of words in errID) - 2) of errID to errID copy "" to errText if errID = "126" then copy "A Menu Events error occurred. The specified application (" & apl & ") has no menu bar." to errText end if if errID = "1713" then copy "A Menu Events error occurred. The specified application (" & apl & Â ") is refusing to interact with other processes, or (if Menu Events extension is locked) with remote processes." to errText end if if errID = "21000" then copy "A Menu Events error occurred. The specified application (" & apl & ") has no such menu (menu id " & MenuID & " was specified)." to errText end if if errID = "21001" then copy "A Menu Events error occurred. The specified application (" & apl & ") has no such menu item (menu item id " & MenuItemID & " was specified)." to errText end if if errID = "21002" then copy "A Menu Events error occurred. The specified application (" & apl & ") has menu item id " & MenuItemID & " of menu id " & MenuID & " disabled." to errText end if if errID = "21003" then copy "A Menu Events error occurred. The specified application (" & apl & ") has another Menu Event pending." to errText end if if errID = "21004" then copy "A Menu Events error occurred. The specified application (" & apl & ") does not support High Level Events." to errText end if if errText is "" then return errID else return {"error", errText} end if end try end DoMenuItem